import request from '@/http/http'
import type { ApiResponse } from "@/http/http"

// 会议室列表查询参数接口
export interface RoomListParams {
    RoomName?: string  // 可选参数
    Location?: string  // 可选参数
    IsSmartRoom?: boolean  // 可选参数
    pageIndex: number  // 页码
    pageSize: number   // 每页大小
}

// 会议室列表项类型
export interface RoomItem {
    Id: number
    Name: string
    Location: string
    Capacity: number
    Manager: string
    ContactPhone: string
    UserName?: string     // 发起人/登录人
    NeedsApproval: boolean
    IsSmartRoom: boolean
    ImageUrl?: string
    Equipments?: string[]
    Remark?: string
}

// 会议室列表响应数据结构
export interface RoomListData {
    TotalCount: number
    TotalPage: number
    Data: RoomItem[]
}

// 新增会议室请求参数接口
// 会议室数据类型定义
export interface RoomData {
    Id: number;
    Name: string;
    Capacity: string;  // 字符串类型
    Location: string;
    Manager: string;
    ContactPhone: string;
    UserName: string;
    NeedsApproval: boolean;
    IsSmartRoom: boolean;
    ImageUrl: string;
    Equipments?: string[];
    Remark?: string;
  }
  
// 更新会议室请求参数接口
export interface UpdateRoomParams {
    Id: number         // 编辑时为会议室ID
    Name?: string      // 会议室名称
    Location?: string      // 会议室位置
    Capacity?: string      // 容纳人数 (数字类型)
    Manager?: string     // 管理员 (字符串类型)
    UserName?: string   // 登录人姓名 发起会议人
    ContactPhone?: string  // 联系电话
    NeedsApproval?: boolean // 是否需要预约审批
    IsSmartRoom?: boolean   // 是否为智能会议室
    ImageUrl?: string      // 会议室图片

}

// 获取会议室列表
export const getRoomList = async (params: RoomListParams): Promise<ApiResponse<RoomListData>> => {
    return request({
        url: 'BaseDataReadAPI/MeetingRoom/GetMeetingRoomList',
        method: 'GET',
        params
    })
}

// const abc = {
//     "Id": 0,
//     "Name": "asgffsas ",
//     "Capacity": "sagssgags",
//     "Location": "gsagsa",
//     "Manager": "asgsga",
//     "ContactPhone": "12asggs3",
//     "UserName": "123gsag",
//     "NeedsApproval": true,
//     "IsSmartRoom": true,
//     "ImageUrl": "1asg23"
// }

// 新增会议室
export const addRoom = async (data: RoomData): Promise<ApiResponse<any>> => {
    return request({
        url: 'BaseDataWriteAPI/MeetingRoom/AddMeetingRoom',
        method: 'POST',
        data:data
    })
}

// 更新会议室信息
export const updateRoom = async (data: UpdateRoomParams): Promise<ApiResponse<any>> => {
    return request({
        url: 'BaseDataWriteAPI/MeetingRoom/UpdateMeetingRoom',
        method: 'PUT',
        data:  data 
    })
}

// 删除会议室
export const deleteRoom = async (roomId: number): Promise<ApiResponse<any>> => {
    return request({
        url: 'BaseDataWriteAPI/MeetingRoom/DeleteMeetingRoom',
        method: 'DELETE',
        params: { Id: roomId }
    })
}

// 上传会议室图片
export const uploadRoomImage = async (file: File): Promise<ApiResponse<any>> => {
    const formData = new FormData()
    formData.append('formFile', file)

    return request({
        url: 'BaseDataWriteAPI/MeetingRoom/Upload',
        method: 'POST',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
} 


// 批量删除会议室
export const deleteRangeRoom = async (roomId: string) => {
    return request({
        url: 'BaseDataWriteAPI/MeetingRoom/DeleteMeetingRoomRange',
        method: 'DELETE',
        params: { Id: roomId }
    })
}